<template>
    <div>
         <el-tabs v-model="record.activeName" @tab-click="handleClick" style="padding-bottom: 15px;" >
            <el-tab-pane label="任务信息" name="1" class="dialog1" >
                <h3 class="dialog-plate-title"><span>基本信息</span></h3>
                <el-form :inline="true" class="demo-form-inline" v-model="record.formData" label-position="right" label-width="180px">
                    <el-form-item :label="record.raskType=='jqBz'?'部件条码':'新机器条码'" ><el-input v-model="record.formData.taskcode" disabled></el-input></el-form-item>
                    <el-form-item label="生产批号"><el-input v-model="record.formData.batchnums" disabled></el-input></el-form-item>
                    <el-form-item label="部装产品名称"  v-if='record.raskType=="jqBz"'>
                        <el-input v-model="record.formData.resourcenameName" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="总装名称"  v-if='record.raskType=="jqZz"'>
                        <el-input v-model="record.formData.resourcenameName" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="测试类型"  v-if='record.raskType=="jqCz"'>
                        <el-input v-model="record.formData.resourcenamename" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="产品型号"><el-input v-model="record.formData.typenums" disabled></el-input></el-form-item>
                    <el-form-item label="业务类型" ><el-input v-model="record.formData.businesstype" disabled></el-input></el-form-item>
                    <el-form-item label="任务创建人"><el-input v-model="record.formData.taskreleasepersonName" disabled></el-input></el-form-item>
                    <el-form-item label="任务创建时间">
                        <el-date-picker v-model="record.formData.taskreleaseaddtime" disabled format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="负责人">
                         <el-input v-model="record.formData.taskperformpersonName" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="任务需完成时间">
                        <el-date-picker v-model="record.formData.taskstartorendtime" disabled format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="计划创建类型">
                        <el-select v-model="record.formData.tasktype" disabled>
                            <el-option label="计划任务" :value="1"></el-option>
                            <el-option label="临时任务" :value="2"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>

                <h3 class="dialog-plate-title"><span>待办信息</span></h3>
                <el-form :inline="true" class="demo-form-inline" v-model="record.formData" label-position="right" label-width="180px">
                    <el-form-item label="任务是否接收">
                        <el-select v-model="record.formData.istaskstart" disabled>
                            <el-option label="否" value="0"></el-option>
                            <el-option label="是" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="接收创建时间">
                        <el-date-picker v-model="record.formData.taskstartaddtime" disabled format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                    </el-form-item>
                </el-form>

                <h3 class="dialog-plate-title"><span>进行中信息</span></h3>
                <el-form :inline="true" class="demo-form-inline" v-model="record.formData" label-position="right" label-width="180px">
                    <el-form-item label="任务是否开始">
                        <el-select v-model="record.formData.istaskbegin" disabled>
                            <el-option label="否" value="0"></el-option>
                            <el-option label="是" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="开始启动时间">
                        <el-date-picker v-model="record.formData.taskbegintime" disabled format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="启动创建时间">
                        <el-date-picker v-model="record.formData.taskbeginaddtime" disabled format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="任务是否结束">
                        <el-select v-model="record.formData.istaskend" disabled>
                            <el-option label="否" value="0"></el-option>
                            <el-option label="是" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="任务结束时间">
                        <el-date-picker v-model="record.formData.taskendtime" disabled format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="结束创建时间">
                        <el-date-picker v-model="record.formData.taskendaddtime" disabled format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="是否已出库">
                        <el-select v-model="record.formData.isoutstorage" disabled>
                            <el-option label="否" :value="0"></el-option>
                            <el-option label="是" :value="1"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="状态">
                        <el-select v-model="record.formData.state" disabled>
                            <el-option label="不合格" :value="0"></el-option>
                            <el-option label="合格" :value="1"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>

                <h3 class="dialog-plate-title"><span>复核信息</span></h3>
                <el-form :inline="true" class="demo-form-inline" v-model="record.formData" label-position="right" label-width="180px">
                    <el-form-item label="任务是否复核">
                        <el-select v-model="record.formData.isreviewtask" disabled>
                            <el-option label="否" value="0"></el-option>
                            <el-option label="是" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="复核执行人"><el-input v-model="record.formData.reviewperson" disabled></el-input></el-form-item>
                    <el-form-item label="复核结果">
                        <el-select v-model="record.formData.reviewresult" disabled>
                            <el-option label="【空】" value="-1"></el-option>
                            <el-option label="正常" value="1"></el-option>
                            <el-option label="异常" value="0"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="复核时间">
                        <el-date-picker v-model="record.formData.reviewtime" disabled format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="复核创建时间">
                        <el-date-picker v-model="record.formData.reviewaddtime" disabled format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
            <el-tab-pane   label="物料输入" name="2" v-if="record.raskType!='jqCs'">
                  <h3 class="dialog-plate-title"><span>物料</span></h3>
                     <el-table :data="inputMateriel.list" stripe border class="table-index"  style="width: 100%;" :header-cell-style="getRowClass">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column prop="nameName" label="物料名称" sortable min-width="170"></el-table-column>
                        <el-table-column prop="code" label="物料条码" sortable min-width="170"></el-table-column>
                        <el-table-column prop="num" label="数量" sortable min-width="100"></el-table-column>
                        <el-table-column prop="isAssembly" label="是否领料"  :formatter='formartIsAssembly' sortable min-width="100"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                            <template slot-scope="scope">
                                <el-button @click="showDialog1('materiel',scope.row)" type="text" size="small">查看物料</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <h3 class="dialog-plate-title" v-if="record.raskType=='jqZz'"><span>部件</span></h3>
                    <el-table :data="part.list" stripe border class="table-index"  style="width: 100%;" :header-cell-style="getRowClass" v-if="record.raskType=='jqZz'">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column prop="nameName" label="物料名称" sortable min-width="170"></el-table-column>
                        <el-table-column prop="code" label="物料条码" sortable min-width="170"></el-table-column>
                        <el-table-column prop="num" label="数量" sortable min-width="100"></el-table-column>
                        <el-table-column prop="isAssembly" label="是否领料"  :formatter='formartIsAssembly' sortable min-width="100"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                            <template slot-scope="scope">
                                <el-button @click="showDialog1('parts',scope.row)" type="text" size="small">查看物料</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
            </el-tab-pane>
            <el-tab-pane  label="装配过程" name="3">
                <h3 class="dialog-plate-title"><span>装配过程过程信息录入</span></h3>
                    <div class="formDemo">
                        <check-form :data="assembly.list"  :isDisabled="assembly.disabled" :footerIsShow="false"></check-form>
                    </div>
            </el-tab-pane>
                <el-tab-pane  label="输出结果" name="4" v-if="record.raskType!='jqCs'">
                    <el-table :data="result.list" stripe border class="table-index"  style="width: 100%;" :header-cell-style="getRowClass">
                    <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                    <el-table-column prop="name" label="名称"    sortable min-width="170"></el-table-column>
                    <el-table-column prop="jqbzResults.length" label="检查项数量"    sortable min-width="170"></el-table-column>
                    <el-table-column prop="createTime" label="创建时间"   sortable min-width="100"></el-table-column>
                    <el-table-column prop="creator" label="创建人"   sortable min-width="100"></el-table-column>
                    <el-table-column fixed="right" label="操作" sortable align="center" width="160">
                        <template slot-scope="scope">
                            <el-button @click="showDialog1('update',scope.row)" type="text" size="small">详情</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
            <el-tab-pane  label="出库记录" name="5" v-if="record.raskType=='jqBz'">
                    <el-table :data="checkOut.list" stripe border class="table-index"   style="width: 100%;" :header-cell-style="getRowClass">
                    <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                    <el-table-column prop="code" label="总装机器编号" sortable min-width="170"></el-table-column>
                    <el-table-column prop="state" label="状态" sortable min-width="170">
                            <template slot-scope="scope">
                            <el-tag type="success" v-if="scope.row.state==1">合格</el-tag>
                            <el-tag type="danger" v-if="scope.row.state==0">不合格</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="createTime" label="创建时间" sortable min-width="170"></el-table-column>
                        <el-table-column prop="creatorName" label="领料人" sortable min-width="170"></el-table-column>
                    <el-table-column prop="recorderName" label="总装记录" sortable min-width="170"></el-table-column>
                    <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                        <template slot-scope="scope">
                            <el-button @click="showDialog1('',scope.row)" type="text" size="small">检验记录</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
         </el-tabs>
         <el-dialog :title="dialog1.title"  width="90%" :visible.sync="dialog1.isShow"  v-dialogDrag :append-to-body="true" :close-on-click-modal='false'>
            <div v-if="record.activeName=='2'" :style="dialogHeightPane">
                <el-table :data="materielPart.list" stripe border class="table-index"  style="width: 100%;" :header-cell-style="getRowClass">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column fixed prop="nameName" label="物料名称" sortable min-width="100"></el-table-column>
                        <el-table-column prop="type" label="产品型号"  min-width="100"></el-table-column>
                        <el-table-column prop="code" label="条码"  min-width="80"></el-table-column>
                        <el-table-column prop="batch" label="批号"  min-width="80"></el-table-column>
                        <el-table-column prop="num" label="数量"  min-width="50"></el-table-column>
                        <el-table-column prop="creatorName" label="领料人"  min-width="60"></el-table-column>
                        <el-table-column prop="state" label="物料状态" min-width="60">
                             <template slot-scope="scope">
                               <el-tag type="success" v-if="scope.row.state==1">合格</el-tag>
                               <el-tag type="danger" v-if="scope.row.state==0">不合格</el-tag>
                               <el-tag type="info" v-if="scope.row.state==-1">报废</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column prop="createTime" label="领料时间" sortable min-width="100"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="120">
                            <template slot-scope="scope">
                                <el-button @click="showDialog2(scope.row)" type="text" size="small" v-if="scope.row.isCheck==1">检验详情</el-button>
                            </template>
                        </el-table-column>
                </el-table>
            </div>
             <div v-if="record.activeName=='4'||record.activeName=='5'" :style="dialogHeightPane">
                  <check-form :data="dialog1.formData"  :isDisabled="true" :footerIsShow="false" ></check-form>
            </div>
        </el-dialog>
        <el-dialog :title="dialog2.title"  width="90%" :visible.sync="dialog2.isShow"  v-dialogDrag :append-to-body="true" :close-on-click-modal='false'>
            <div  :style="dialogHeightPane">
                <check-form :data="dialog2.formData"  :isDisabled="true" :footerIsShow="false" ></check-form>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import pdf from 'vue-pdf';
import api from '@/axios/api.js'
import machineHttp from '@/axios/machine.js'
import checkForm from './checkForm.vue'
export default {
    components:{
        checkForm
    },
    props:{
        record:Object
    },
    data(){
        return {
            inputMateriel:{
                list:[]
            },
            technicalStandard:[],
            drawingList:[],
            sopList:[],
            assembly:{
                list:[],
                disabled:true
            },
            result:{
                list:[]
            },
            checkOut:{
                list:[],
            },
            part:{
                list:[]
            },
            dialog1:{
                title:'',
                isShow:false,
                content:'',
                formData:[]
            },
             dialog2:{
                title:'',
                isShow:false,
                formData:[]
            },
            materielPart:{
                list:[]
            },
           drawingPdf:{
                src:'',
                instructionsPageApply:1,
                instructionsNumPagesApply: 0,
                instructionsRotateApply: 0,
            },
            dialogHeightPane: {
                height: (document.documentElement.clientHeight - 180) + 'px',
                overflowY: 'auto'
            },
            dialogTableHeight: document.documentElement.clientHeight - 260,
        }
    },
    methods:{
         formartIsAssembly(row, column, cellValue, index){
            return cellValue == 1 ? '是' : (cellValue == 0 ? '否' : '')
        },
        handleClick(tab, event){
            let self = this;
             switch(self.record.activeName){
                case '2':
                    self.getInputList();
                     break;
                case '3':
                    self.getProcessList();
                     break;
                case '4':
                    self.getResultList();
                     break;
                case '5':
                    self.getCheckOutList();
                     break;
             }
        },
        showDialog1(type,row){
            let self = this;
            switch(self.record.activeName){
                case '2':
                   self.dialog1.title= type=='materiel'?"入库物料":"入库部件";
                   self.getSelectmaterie(type,row.id);
                break;
                case '4':
                     self.dialog1.title = '输出检查记录'
                    if(self.record.raskType== 'jqBz'){
                        self.dialog1.formData = row.jqbzResults;
                    }else if(self.record.raskType== 'jqZz'){
                        self.dialog1.formData = row.jqzzResults;
                    }
                    break;
                case '5':
                    self.dialog1.title = '出库检查记录';
                    api.checkOutCheackInfo(row.mid).then(res=>{
                        self.dialog1.formData = res.content;
                    });
                    break;

            }
            self.dialog1.isShow=true;

        },
        getInputList(){/**获取物料输入列表 */
            let self = this;
            switch(self.record.raskType){
                case 'jqBz':
                    api.inputMaterielList(self.record.formData.tid).then(res=>{
                        self.inputMateriel.list = res.content;
                    })
                    break;
                 case 'jqZz':
                    api.zzMaterieList(self.record.formData.tid).then(res=>{
                        self.inputMateriel.list=res.content;
                    })
                    api.zzPartsList(self.record.formData.tid).then(res=>{
                        self.part.list=res.content;
                    })
                    break;
            }
        },
        getProcessList(){/**获取装配过程记录 */
            let self = this;
            switch(self.record.raskType){
                case 'jqBz':
                    api.assemblyList(self.record.formData.tid).then(res=>{
                        self.assembly.list=res.content;
                    })
                break;
                 case 'jqZz':
                    api.zzAssembly(self.record.formData.tid).then(res=>{
                    self.assembly.list=res.content;
                })
                break;
                case 'jqCs':
                    machineHttp.jqcsMachineTestProecssList(self.record.formData.tid).then(res=>{
                    self.assembly.list = res.content;
                })
                break;
            }
        },
        getResultList(){
            let self = this;
            switch(self.record.raskType){
                case 'jqBz':
                    api.resultList(self.record.formData.tid).then(res=>{
                        self.result.list=res.content;
                    })
                break;
                 case 'jqZz':
                    api.jqzzResultList(self.record.formData.tid).then(res=>{
                        self.result.list=res.content;
                    })
                break;

            }
        },
        getCheckOutList(){
             let self = this;
            api.checkoutList(self.record.formData.tid).then(res=>{
                    self.checkOut.list=res.content;
            })
        },
        getSelectmaterie(type,id){
            let self = this;
            switch(self.record.raskType){
                case 'jqBz':
                    api.selectMaterieList(id).then(res=>{
                        self.materielPart.list=res.content;
                    })
                    break;
                 case 'jqZz':
                     type=='materiel'? api.zzSelectMaterial(id).then(res=>{self.materielPart.list=res.content;}):api.zzSelectParts(id).then(res=>{
                        self.materielPart.list=res.content;
                    })
                    break;
            }
        },
        showDialog2(row){
            let self = this;
            debugger;
            switch(self.record.raskType){
                case 'jqBz':
                    self.dialog2.title = '物料检验记录'
                    api.materialListCheck(row.id).then(res=>{
                        self.dialog2.formData=res.content;
                    })
                    break;
                case 'jqZz':
                    self.dialog2.title = self.dialog1.title=="入库物料"?"物料检验记录":"部件检验记录"
                    self.dialog1.title=="入库物料"?api.checkZzMaterialInfo(row.id).then(res=>{
                       self.dialog2.formData=res.content;
                    }):api.checkPartsInfo(row.id).then(res=>{
                       self.dialog2.formData=res.content;
                    })
                break;
            }
            self.dialog2.isShow=true;
        }
    }
}
</script>
<style scoped>

</style>


